home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
MacWorld 1999 July
/
Macworld (1999-07).dmg
/
Shareware World
/
Info
/
For Developers
/
Mops 3.4.sea
/
Mops source
/
More classes
/
Container
< prev
next >
Wrap
Text File
|
1998-10-01
|
2KB
|
79 lines
(*
Class Container is intended to support persistent objects. Once an object
implements SEND: and BRING: correctly, we have to somehow link it to a file to
make it persistent. The Container class represents one way that this can be
done.
Class Container is a subclass of File, and has an INIT: method in which you
pass in the address of an object. Then when you pass OPEN: and SAVE: messages
to the Container, the Container sends BRING: and SEND: messages respectively,
to the object.
The fact that we only link one object to the Container doesn't mean that the
number of objects in the Container is in any way limited, since the object can
be a HandleList which can be a collection of an arbitrary number of objects
from arbitary classes. HandleList implements SEND: and BRING: properly (in a
way that accounts for the objects in the list being of arbitrary classes). So,
after you have sent OPEN: to a Container, all the objects in the container will
have been read into memory. And when you send SAVE:, they are all written out
to the file. If you don't want all your objects to be in memory at the same
time, you can use several containers.
This scheme is very flexible, and will probably be sufficient for most needs.
*)
:class CONTAINER super{ file }
dicaddr ^obj
bool setup?
:m INIT: ( ^obj -- )
put: ^obj
false -> setup?
;m
:m OPEN: { \ len #elements -- }
open: super ?EXIT
^base get: ^obj bring: []
close: super drop
;m
:m SAVE: { typ crtr addr1 len1 addr2 len2 \ pos -- }
get: setup?
NIF addr1 len1 addr2 len2 stdPut: self 0EXIT
create: self OK?
typ crtr set: self
true -> setup?
ELSE
open: super OK?
0 setEOF: super OK?
THEN
^base send: [ get: ^obj ]
close: super drop
;m
;class
endload
container CC
handlelist HH
hh init: cc
" hoho" name: CC
' string newobj: hh " hi there" obj: hh put: []
' string newobj: hh " ho there" obj: hh put: []
' string newobj: hh " what ho there" obj: hh put: []
10 ' array newobj: hh 123 9 obj: hh to: []
456 8 obj: hh to: []
endload